package com.inifitness.common.result;

import java.io.Serializable;
import java.util.List;

import com.baomidou.mybatisplus.core.metadata.IPage;

import lombok.Data;

/**
 * 分页请求结果
 *
 * @author sunjinfeng
 * @version 1.0.0
 * @since 2024/04/18 11:00:00
 */
@Data
public class PageResult<T> implements Serializable {

  private String code;
  private Data<T> data;
  private String msg;

  public static <T> PageResult<T> success(IPage<T> page) {
    PageResult<T> result = new PageResult<>();
    result.setCode(ResultCode.SUCCESS.getCode());

    Data<T> data = new Data<>();
    data.setList(page.getRecords());
    data.setTotal(page.getTotal());

    result.setData(data);
    result.setMsg(ResultCode.SUCCESS.getMsg());
    return result;
  }

  @lombok.Data
  public static class Data<T> implements Serializable {

    private List<T> list;
    private long total;
  }
}
